#!/bin/bash
dhcpcd
timedatectl set-ntp true

lsblk
echo "choose a disk to wipe"
read wipedisk

fdisk /dev/$wipedisk

echo -e "which type is your device?\n1.uefi or virtualbox 2.mbr "
read uefi


lsblk
echo "input boot partion"
read boot
echo "input root partion"
read root
mkfs.ext4 /dev/$root
mount /dev/$root /mnt
if [ $uefi -eq 1 ];then
echo -e "have you already built efi already?\n1.no 2.yes"
read alreadyEfi
if [ $alreadyEfi -eq 1 ];then
mkfs.fat -F32 /dev/$boot
else
echo "ok,I just mount it"
fi
mkdir -p /mnt/boot/efi
mount /dev/$boot /mnt/boot/efi
else
echo -e "have you added boot flag for boot partion?\n1.no 2.yes"
read ifBoot
if [ $ifBoot -eq 1 ];then
echo "add optin (a) to boot partion"
fdisk /dev/$wipedisk
fi
echo -e "have you already built boot already?\n1.no 2.yes"
read alreadyBoot
if [ $alreadyBoot -eq 1 ];then
mkfs.ext4 /dev/$boot
else
echo "ok,I just mount it"
fi
mkdir -p /mnt/boot
mount /dev/$boot /mnt/boot
fi


sed -i "7i# busf1\nServer = http://mirrors.bfsu.edu.cn/archlinux/\$repo/os/\$arch\n## bfsu2\nServer = https://mirrors.bfsu.edu.cn/archlinux/\$repo/os/\$arch\n# 清华大学\nServer = https://mirrors.tuna.tsinghua.edu.cn/archlinux/\$repo/os/\$arch\n" /etc/pacman.d/mirrorlist
pacman -Syy

pacstrap /mnt base linux linux-firmware   base-devel  vim vi nano dhcpcd --noconfirm
genfstab -U /mnt >> /mnt/etc/fstab

cp archchroot.sh archchroot2.sh archchroot3.sh custom.sh custom_wayland.sh custom_server.sh 99-gpu.conf 99-gpu-nvidia_prefer.conf nvidia_driver.sh switch.sh /mnt/root/
echo -e "for full:\nplease run cd ;chmod +x  archchroot.sh ;./archchroot.sh \nfor lite:\nplease run cd ;chmod +x  archchroot2.sh ;./archchroot2.sh" 
arch-chroot /mnt

